//
//  AppDelegate.m
//  NPS
//
//  Created by jadd on 15/10/12.
//  Copyright © 2015年 jadd. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


+ (AppDelegate *)shareInstance {
    return [[UIApplication sharedApplication] delegate];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];


    //2015年07月22日17:03:50 友盟统计 wpz
    [MobClick startWithAppkey:globalUMengAppKey reportPolicy:BATCH  channelId:nil];
    //2015-06-09 增加友盟 反馈 appkey
    //[UMFeedback setAppkey:globalUMengAppKey];
    
    //2015-06-04 dhy 增加友盟社会化组件appKey
    [UMSocialData setAppKey:globalUMengAppKey];
    //设置QQAppId、appSecret，分享url
    [UMSocialQQHandler setQQWithAppId:globalQQAppID  //16进制为：41d825c4
                               appKey:globalQQAppKey
                                  url:K_UMeng_WeiChat_Url];
    //设置微信AppId、appSecret，分享url
    [UMSocialWechatHandler setWXAppId:globalWeiXinAppID
                            appSecret:globalWeiXinSecret
                                  url:K_UMeng_WeiChat_Url];
    //打开新浪微博的SSO开关，设置新浪微博回调地址，这里必须要和你在新浪微博后台设置的回调地址一致。若在新浪后台设置我们的回调地址，“http://sns.whalecloud.com/sina2/callback”，这里可以传nil ,需要 #import "UMSocialSinaHandler.h"
    //[UMSocialSinaSSOHandler openNewSinaSSOWithRedirectURL:K_UMeng_Sina_Callback];
        
    self.navController = nil;
    [MyGlobal sharedVariables].isReLogin = NO;
    
    LoginViewController *controller = [[LoginViewController alloc] init];
    self.navController = [[UINavigationController alloc] initWithRootViewController:controller];
    self.window.rootViewController = self.navController;
    

    if (![Config hasLogin])
    {
        StoresInfoController *store = [[StoresInfoController alloc] init];
//        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:store];
//        store.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//        [controller presentViewController:nav animated:YES completion:^{
//            NSLog(@"");
//        }];
        [self.navController pushViewController:store animated:NO];
    
    }
    

//    NSDictionary * dict=[NSDictionary dictionaryWithObject:[UIColor colorWithHexString:K_Global_ColorHexString_Store] forKey:NSForegroundColorAttributeName];
//    navController.navigationBar.titleTextAttributes= dict;
    
    //navController.navigationBar.barTintColor = BButtonTypeWarning;
    //navController.navigationBar.tintColor = BButtonTypeWarning;
    

  
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:K_FirstStartKey] boolValue] == NO
        ) {
        //暂时没有引导效果
        //self.introWindow.hidden = NO;
        
    }
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
                [self showNotWifiAlertView];
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                break;
            default:
                break;
        }
        NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
    }];
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)showNotWifiAlertView {
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"您正在使用蜂窝移动网络" message:@"建议在WiFi下使用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alertView show];
}


#pragma mark - Umeng social
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return  [UMSocialSnsService handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url];
}


#pragma mark - setter, getter
- (UIWindow *)introWindow {
    if (_introWindow == nil) {
        self.introWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        _introWindow.windowLevel = UIWindowLevelAlert;
        IntroductionViewController * introVC = [[IntroductionViewController alloc] init];
        _introWindow.rootViewController = introVC;
    }
    return _introWindow;
}



@end
